﻿package src.states{
	import flash.display.DisplayObjectContainer;
	
	public class GameStatesMachine {
		private var currentState:GameState;
		
		private var gameplayState:GameState;
		private var newLevelState:GameState;
		private var endGameState:GameState;
		private var endLevelState:GameState;
		
		public function GameStatesMachine(contentHolder:DisplayObjectContainer) {
			initStates(contentHolder);
		}
		
		private function initStates(holder:DisplayObjectContainer):void {
			gameplayState = new Gameplay(holder, this);
			newLevelState = new NewLevel(holder, this);
			endLevelState = new EndLevel(holder, this);
			endGameState = new EndGame(holder, this);
			currentState = new GameState(holder, this);
		}
		
		public function setCurrentState(state:GameState)
		{
			currentState.dispose();
			currentState = state;
			currentState.init();
		}
		
		public function getCurrentState():GameState {
			return currentState;
		}
		
		public function getGameplayState():GameState {
			return gameplayState;
		}
		
		public function getNewLevelState():GameState {
			return newLevelState;
		}
		
		public function getEndLevelState():GameState {
			return endLevelState;
		}
		
		public function getEndGameState():GameState {
			return endGameState;
		}
		
		public function resetAllStates():void {
			gameplayState.restart();
			newLevelState.restart();
			endLevelState.restart();
			endGameState.restart();
		}

	}
	
}
